package com.orifine.web;




public abstract class Validator implements Cloneable {
	private Property domain;
	
	public Validator setDomain(Property domain){
		this.domain = domain;
		return this;
	}
	
	public Property getDomain(){
		return domain;
	}
	
	private Object[] values;
	
	public Validator define(Object... values) {
		try {
			Validator clone = (Validator)super.clone();
			clone.values = values;
			
			if(!clone.lazy()){
				clone.result();
			}
			return clone;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}
	
	protected abstract boolean execute(Object... values);
	public abstract Property property();
	
	private Boolean resultValue;
	
	public Boolean result(){
		if(this.resultValue == null){
			this.resultValue = execute(this.values);
		}
		return this.resultValue;
	}
	
	protected boolean lazy(){
		return true;
	}
}
